package com.songlanyun.modules.systeminfo.controller.admin;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.songlanyun.common.annotation.RepeatSubmit;
import com.songlanyun.common.annotation.SysLog;
import com.songlanyun.common.utils.BeanUtil;
import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.modules.user.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.songlanyun.modules.systeminfo.entity.SystemInfo;
import com.songlanyun.modules.systeminfo.service.SystemInfoService;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;


/**
 * 平台信息
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-12-02 13:07:36
 */
@RestController
@RequestMapping("admin/system/info")
public class SystemInfoAdminController extends AbstractController {
    @Autowired
    private SystemInfoService systemInfoService;


    /**
     * 信息
     */
    @GetMapping("/info")
//    @RequiresPermissions("systeminfo:systemInfo:info")
    public R info() {
        SystemInfo info = systemInfoService.info();

        return R.ok().put("data", info);


    }

    /**
     * 保存
     */
    @SysLog("保存修改平台信息")
    @RepeatSubmit(value = "3")
    @PostMapping("/save")
//    @RequiresPermissions("systeminfo:systemInfo:save")
    public R save(@RequestBody SystemInfo systemInfo) {
        verifyAdmin();
        ValidatorUtils.validateEntity(systemInfo);

        SystemInfo info = systemInfoService.info();
        if (info == null) {
            //保存
            systemInfoService.save(systemInfo);
        } else {
            //修改
           BeanUtil.copyPropertiesIgnoreNull(systemInfo,info);
            systemInfoService.updateById(info);
        }

        return R.ok();
    }


}
